package com.szcinda.controller;

import com.szcinda.controller.configuration.UserLoginToken;
import com.szcinda.repository.Notice;
import com.szcinda.service.PageResult;
import com.szcinda.service.dto.notice.NoticeCreateDto;
import com.szcinda.service.dto.notice.NoticeQueryDto;
import com.szcinda.service.dto.notice.NoticeService;
import com.szcinda.service.dto.notice.NoticeUpdateDto;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("notice")
public class NoticeController {

    private final NoticeService noticeService;

    public NoticeController(NoticeService noticeService) {
        this.noticeService = noticeService;
    }

    @UserLoginToken
    @PostMapping("create")
    @OperationLogAnnotation(operDesc = "创建系统公告", operModel = "系统公告")
    public Result<String> create(@RequestBody NoticeCreateDto createDto) {
        noticeService.create(createDto);
        return Result.success();
    }

    @UserLoginToken
    @PostMapping("update")
    @OperationLogAnnotation(operDesc = "修改系统公告", operModel = "系统公告")
    public Result<String> update(@RequestBody NoticeUpdateDto updateDto) {
        noticeService.update(updateDto);
        return Result.success();
    }

    @UserLoginToken
    @GetMapping("delete/{id}/{userId}")
    @OperationLogAnnotation(operDesc = "删除系统公告", operModel = "系统公告")
    public Result<String> delete(@PathVariable String id, @PathVariable String userId) {
        noticeService.delete(id, userId);
        return Result.success();
    }

    @UserLoginToken
    @GetMapping("getTodayNotice/{organizationId}")
    public Result<List<Notice>> getTodayNotice(@PathVariable String organizationId) {
        return Result.success(noticeService.getAll(organizationId));
    }


    @PostMapping("query")
    public PageResult<Notice> query(@RequestBody NoticeQueryDto queryDto) {
        return noticeService.query(queryDto);
    }

    @PostMapping("queryHistory")
    public PageResult<Notice> queryHistory(@RequestBody NoticeQueryDto queryDto) {
        return noticeService.queryHistory(queryDto);
    }
}
